package com.campus.marketplace.controller;

import com.campus.marketplace.entity.Report;
import com.campus.marketplace.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/reports")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @PostMapping
    public ResponseEntity<Report> submitReport(@RequestBody Report report) {
        return ResponseEntity.ok(reportService.submitReport(report));
    }

    @GetMapping("/user/{userId}")
    public ResponseEntity<List<Report>> getUserReports(@PathVariable Long userId) {
        return ResponseEntity.ok(reportService.getUserReports(userId));
    }

    @GetMapping("/target/{targetType}/{targetId}")
    public ResponseEntity<List<Report>> getTargetReports(
            @PathVariable String targetType,
            @PathVariable Long targetId) {
        return ResponseEntity.ok(reportService.getTargetReports(targetType, targetId));
    }

    @GetMapping("/pending")
    public ResponseEntity<List<Report>> getPendingReports() {
        return ResponseEntity.ok(reportService.getPendingReports());
    }

    @GetMapping("/{reportId}")
    public ResponseEntity<Report> getReportById(@PathVariable Long reportId) {
        return ResponseEntity.ok(reportService.getReportById(reportId));
    }

    @PostMapping("/{reportId}/process")
    public ResponseEntity<Void> processReport(
            @PathVariable Long reportId,
            @RequestParam String status,
            @RequestParam String processResult) {
        reportService.processReport(reportId, status, processResult);
        return ResponseEntity.ok().build();
    }

    @PutMapping("/{reportId}/status")
    public ResponseEntity<Void> updateReportStatus(
            @PathVariable Long reportId,
            @RequestParam String status) {
        reportService.updateReportStatus(reportId, status);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/target/{targetType}/{targetId}/count")
    public ResponseEntity<Long> getReportCount(
            @PathVariable String targetType,
            @PathVariable Long targetId) {
        return ResponseEntity.ok(reportService.getReportCount(targetType, targetId));
    }

    @GetMapping("/type/{reportType}/status/{status}")
    public ResponseEntity<List<Report>> getReportsByTypeAndStatus(
            @PathVariable String reportType,
            @PathVariable String status) {
        return ResponseEntity.ok(reportService.getReportsByTypeAndStatus(reportType, status));
    }
}